package com.mai.demo.exception.handler;

/**
 * @className: GlobalExceptionHandler
 * @author: Wang
 * @date: 2024/12/23 下午2:02
 * @Version: 1.0
 */

import com.mai.demo.entity.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.UncheckedIOException;

@RestControllerAdvice
public class GlobalExceptionHandler {

//    @ExceptionHandler(UncheckedIOException.class)
//    public void handleUncheckedIOException(UncheckedIOException e) {
//        e.printStackTrace();
//        // ignore
//    }

    @ExceptionHandler(RuntimeException.class)
    public R<?> handleRuntimeException(RuntimeException e) {
        return R.fail(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R<?> handleException(Exception e) {
        return R.fail("系统异常，请稍后再试");
    }

}
